package com.ly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.entity.Message;
import com.ly.mapper.MessageMapper;
import com.ly.pojo.dto.MessageDTO;
import com.ly.pojo.vo.MessageVO;
import com.ly.service.MessageService;
import com.ly.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author : 黑渊白花
 * @ClassName MessageServiceImpl
 * @date : 2025/2/8 22:31
 * @Description
 */
@Service
@Slf4j
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public IPage<MessageVO> getAllPage(MessageDTO messageDTO) {
        Integer pageNum = messageDTO.getPageNum();
        Integer pageSize = messageDTO.getPageSize();
        String name = messageDTO.getName();
        IPage<MessageVO> page = new Page<>(pageNum,pageSize);
        IPage<MessageVO> allPage = messageMapper.getAllPage(page,name);
        return allPage;
    }

    @Override
    public void reply(Message message) {
        Date d = new Date();
        message.setBackTime(d);
        messageMapper.updateById(message);
    }

    @Override
    public Result getByStuId(Integer stuId) {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("stu_id",stuId);
        List<Message> list = messageMapper.selectList(qw);
        return Result.success(list);
    }
}
